<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cells {
    margin-top: 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .weui-cell {
    background: #fff;
  }
  .weui-cells__title {
    text-align: left;
  }
  .oitem {
    padding: 3px;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }

  .clearfix:after {
    content: ".";
    display: block;
    font-size: 0;
    height: 0;
    clear: both;
    visibility: hidden;
  }
  .clearfix {
    display: inline-table;
  }
  *html .clearfix {
    height: 1%;
  }
  .clearfix {
    display: block;
  }
  *+html .clearfix {
    min-height: 1%;
  }
  .che_tit{
    text-align:center;
    padding:20px;
  }
  .ul_pro{
    background-color:#CED3D9;
    text-align:center;
    padding:4px 2px;
    font-size:14px;
  }
  .ul_pro li{
    float:left;
    width:11.11%;
    padding:2px;
    box-sizing: border-box;
    list-style: none;
  }
  .ul_pro .li_close{
    float:right;
    width:22.22%;
  }
  .ul_pro .li_close span{
    background-color:#ACB3BB;
  }
  .ul_pro .li_clean{
    float:right;
    width:22.22%;
  }
  .ul_pro li span{
    display:block;
    background-color:#fff;
    border-radius:4px;
    box-shadow: 2px 2px 2px #888888;
    /* max-width:48px; margin:0 auto; */
    line-height:32px;
    padding-top:2px;
  }
  .ul_pro li span:active{
    background-color:#4DA9F2;
    color:#fff;
  }
  .ul_input{
    width:auto;
    margin:0 auto;
  }
  .ul_input li{
    float:left;
    width:12%;
    padding:2px;
    text-align:center;
    list-style: none;
  }
  .ul_input li span{
    display: block;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 30px;
    margin: 0 auto;
    height: 30px;
    line-height: 30px;
  }
  .ul_keybord{
    background-color:#CED3D9;
    text-align:center;
    padding:4px 2px;
    font-size:14px;
  }
  .ul_keybord li{
    float:left;
    width:10%;
    padding:2px;
    box-sizing: border-box;
    list-style: none;
  }
  .ul_keybord .ikey20{
    margin-left:5%;
  }
  .ul_keybord .li_w{
    width:11.11%;
  }
  .ul_keybord .li_close{
    float:right;
    width:22.22%;
  }
  .ul_keybord .li_close span{
    background-color:#ACB3BB;
  }
  .ul_keybord .li_clean{
    float:right;
    width:22.22%;
  }
  .ul_keybord li span{
    display:block;
    background-color:#fff;
    border-radius:4px;
    box-shadow: 2px 2px 2px #888888;
    /* max-width:48px; margin:0 auto; */
    line-height:32px;
    padding-top:2px;
  }
  .ul_keybord li span:active{
    background-color:#4DA9F2;
    color:#fff;
  }
  .weui-label{
    width: 130px;
  }
</style>
<template>
  <div>
    <div style="height: 50px; line-height: 50px; background: #f7f7f7; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      调度信息
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="../../assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="weui-cells weui-cells_form">
<!--      <form action="/sales/Sellform!saveOrUpdate.action?openid=${openid}" method="post" id="formid">-->
      <form action="/api/sellform/add" method="post" id="formid">
        <input  name="guid"  id="guid"   type="hidden"  :value="guid" />
        <!--<input  name="openid"  id="openid"   type="hidden"  value="o4kfOwnSU0EZz9GmGb6-3IHVfCMc" />-->
        <input  name="storermguid"  id="storermguid"   type="hidden"   />



        <input  name="quitSRType"  id="quitSRType"   type="hidden"  />
        <input  name="sellType"  id="sellType"   type="hidden"  value="sellDispatch" />
         <div class="weui-cells weui-cells_form">
           <div class="weui-cell">
             <div class="weui-cell__hd"><label class="weui-label">出库类型：</label></div>
             <div class="weui-cell__bd">
               <input class="weui-select" type="text" id="shrtype" name="shrtype"   placeholder="请选择出库类型" >
             </div>
           </div>



          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">出库库房：</label></div>
            <div class="weui-cell__bd">
              <input class="weui-select" type="text" id="storermname" name="storermname" :value="adata.name"  placeholder="请选择库房信息" >
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">发货联系人：</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input"   id="delicontact" name="delicontact" :value="adata.contact"  placeholder=" 请输入发货联系人">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">联系电话:</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number" id="delicontacttel" name="delicontacttel" :value="adata.contacttel"  placeholder=" 请输入发货人手机号">
            </div>
          </div>

          <div class="weui-cell">
            <div class="weui-cell__hd"><label id='unqualifiedchkrateDiv' class="weui-label">发货地址：</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input"   type="text" id='deliprovince' name="deliprovince" >
            </div>
          </div>

          <div class="weui-cell">
            <div class="weui-cell__hd"><label  class="weui-label">详细地址:</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" id='deliaddress' name="deliaddress" :value="adata.address" placeholder=" 请输入发货详细地址">
            </div>
          </div>
        </div>

       <div class="weui-btn-area">
          <a class="weui-btn weui-btn_primary halfbtn subbtn"  href="javascript:" @click="send">提交</a>
          <a class="weui-btn weui-btn_primary halfbtn"  href="javascript:" @click="$router.back(-1)" id="sub">返回</a>
        </div>
      </form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SendCar',

  data () {
    return {
      guid : "",
      nodeid : "",
      status: '',
      adata: {}
    }
  },
  mounted () {
    this.nodeid = this.$route.query.nodeid;
    this.status = this.$route.query.status;
    //
    this.sellDispatch();
    this.loadshrtype();
    $("#deliprovince").cityPicker({
      title: "请选择发货地址",
    });
  },
  methods: {
    send: function() {
      if(!checkSubmit()){
        return;
      }
      //防止重复提交
      $('.subbtn').attr("disabled",true).css("pointer-events","none");

      this.axios({
        method: 'post',
        responseType: 'json',
        headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" },
        url: '/sales/Sellform!sendCar.action?nodeid=' + this.nodeid + '&status=' + this.status,
        params: this.serialize2Obj($("#formid").serializeArray())
      }).then(response => {
        //恢复提交按钮可点击
        $('.subbtn').attr('disabled', false).css("pointer-events","auto");

        if (response.data.info == 'ok') {
          this.toastSuccess('操作成功!');
          this.$router.push({name: 'Sellform'});
        } else if (response.data.info == 'canotopt') {
          this.toastError('不允许的操作');
        } else {
          this.toastError('操作失败!');
        }
      }).catch(function (error) {
        //恢复提交按钮可点击
        $('.subbtn').attr('disabled', false).css("pointer-events","auto");
        this.toastError('系统错误');
      });
},
    serialize2Obj: function (data) {
      var obj = {};
      $.each(data,function(i,v){
        obj[v.name] = v.value;
      })
      return obj;
    },loadstoreroom:function (shrtype){
      let that = this;
      this.guid = this.$route.query.guid;
      $.ajax({
        url: '/repository/Storeroom!getStoreroomJson.action',
        data: {shrtype: shrtype, enable: 1},
        type: "post",
        dataType: "json",
        success: function(res) {
          if (res.info != null) {
            var data = res.info;
            var datalist = new Array;

            $.each( data, function( index, itsm ) {
              var info = { "title": itsm.name, "value": itsm.guid, "storeroom":itsm };
              datalist.push(info);
            });
            $('#storermname').select("update", {
              title: "库房信息",
              items: datalist,
              onChange: function (data) {
                if(data.origins[0] != undefined && data.origins[0] !=null){
                that.adata = data.origins[0].storeroom;
                $('input[name="storermguid"]').val($('#storermname').data('values'));
                $('#deliprovince').val(that.adata.province + " " + that.adata.city + " " +that.adata.area);
                }
              }
            });
          } else {
            that.toastError('系统出现异常!');
          }
        },
        complete: function () {

        }
      });
    },loadshrtype:function (){
        let that = this;
        this.guid = this.$route.query.guid;
        $.ajax({
            url: '/repository/Storeroom!getShrtype.action',
            data: {},
            type: "post",
            dataType: "json",
            success: function(res) {
                if (res.info != null) {
                    var data = res.info;
                    var datalist = new Array;
                    $.each( data, function( index, itsm ) {
                        var info = { "title": itsm.dicttext, "value": itsm.dictkey  };
                        datalist.push(info);
                    });
                    $('#shrtype').select({
                        title: "出库类型",
                        items: datalist,
                        onChange: function (data) {
                            var shrtype =    $('#shrtype').data('values');
                            $('#quitSRType').val(shrtype)
                            if( shrtype != undefined){
                                that.loadstoreroom(shrtype);
                                that.clearOption();
                            }
                        }
                    });
                } else {
                    that.toastError('系统出现异常!');
                }
            },
            complete: function () {

            }
        });
    },
    sellDispatch: function (){
      var that = this;
      that.guid = this.$route.query.guid;
      $.ajax({
        url: '/sales/Sellform!sellDispatch.action',
        data: {guid:that.guid},
        type: "post",
        dataType: "json",
        success: function(res) {
            console.log('res' ,res );


          if (res.info != 'error' && res.info != '') {
            var data = res.info;
            $('#storermname').val(data.storeroomname);
            $('#storermguid').val(data.storermguid);
            $('#delicontact').val(data.delicontact);
            $('#delicontacttel').val(data.delicontacttel);
            $('#deliprovince').val(data.deliprovince + " " + data.delicity + " " +data.delidistrict);
            $('#shrtype').val(data.quitSRTypeName);

            $('#deliaddress').val(data.deliaddress);
            that.loadstoreroom(data.quitSRType);

          } else {
            that.toastError('系统出现异常!');
          }
        },
        complete: function () {

        }
      });
    },
      clearOption:function(){
          $('#storermname').val('');
          $('#storermguid').val('');
          $('#delicontact').val('');
          $('#delicontacttel').val('');
          $('#deliprovince').val('');
          $('#deliaddress').val('');

      }

  }
}

/**
 * 提交之前的校验
 */
function checkSubmit(){
  if(isEmpty("storermguid")){
    alert("请选择库房");
    return false;
  }
  if(isEmpty("delicontact")){
      alert("请填写发货联系人");
      return false;
    }
    if(isEmpty("delicontacttel")){
      alert("请填写发货联系人手机号");
      return false;
    }
    if(isEmpty("deliprovince")){
      alert("请填写发货地址");
      return false;
    }
    if(isEmpty("deliaddress")){
      alert("请填写发货详细地址");
      return false;
    }


  return true;
}

function isEmpty(domID){
  return $('#' + domID).val() == "" || $('#' + domID) == null;
}


</script>
